package com.climb.moive.dao.impl;

import com.climb.moive.dao.AdminDao;
import com.climb.moive.entity.Admin;
import com.climb.moive.framework.jdbc.BeanPropertyRowMapper;
import com.climb.moive.framework.jdbc.JdbcTemplate;
import com.climb.moive.framework.jdbc.RowMapper;
import com.climb.moive.util.JdbcUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Administrator
 */
public class AdminDaoImpl implements AdminDao {
    @Override
    public Admin login(Admin admin) throws SQLException {
        String sql = "select id, account, password from admin where account=? and password=?";

        Connection connection=null;
        try {
            connection=JdbcUtils.getConnection();
            JdbcTemplate jdbcTemplate=new JdbcTemplate(connection);
            RowMapper<Admin> memberRowMapper=new BeanPropertyRowMapper<>(Admin.class);
            admin = jdbcTemplate.queryForObject(sql,memberRowMapper,admin.getAccount(), admin.getPassword());
        } finally {
            JdbcUtils.close(connection);
        }

        return admin;
    }
}
